package com.example.controller;

import com.example.biz.AnswersBiz;
import com.example.biz.TopicBiz;
import com.example.biz.TopictypeBiz;
import com.example.dao.TeacherMapper;
import com.example.entity.Answers;
import com.example.entity.Teacher;
import com.example.entity.Topic;
import com.example.entity.Topictype;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("topic")
public class TopicController {
    @Resource
    private TopictypeBiz topictypeBiz;
    @Resource
    private TopicBiz topicBiz;
    @Resource
    private AnswersBiz answersBiz;
    @GetMapping("showtype")
    public List<Topictype> showtype(){
       return topictypeBiz.queryAll();
    }
    @GetMapping("showtopic")
    public Map<Integer,List<Answers>> showtopic(@PathVariable Integer ttype){
       List<Topic> list= topicBiz.queryByType(ttype);
        Map<Integer,List<Answers>> map=new HashMap<Integer, List<Answers>>();
       for(Topic t:list){
           map.put(t.getTid(),answersBiz.queryByTid(t.getTid()));
       }
       return map;
    }
    @GetMapping("check")
    public Integer check(List<Topic> list){
    return  topicBiz.checkright(list);
    }
}
